<?php
Class AdminModel extends Model{
	Public $validate = array(
		array('username','nonull','用户名不能为空',2,3),
		array('password','nonull','密码不能为空',2,1),
		array('repassword','confirm:password','确认密码不一致',2,3)
		);

	Public function addUser(){
		$data['username'] = Q('post.username');
		$data['password'] = Q('post.password');
		$data['repassword'] = Q('post.repassword');
		$data['logintime'] = time();
		if($this->create($data)){
			if($this->where(array('username'=>$data['username']))->find()){
				$this->error = $data['username']."已存在";
				return false;
			}
			$data['password']=md5($data['password']);
			return $this->add($data);
		}
	}

	Public function editUser(){
		$data['uid'] =Q('uid',0,'intval');
		$data['username'] = Q('post.username');
		$data['password'] = Q('post.password');
		$data['repassword'] = Q('post.repassword');
		if($this->create($data)){
			if($data['password']){
				$data['password']=md5($data['password']);
			}
			return $this->save($data);
		}
	}
}